home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / programs / win_events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  10.0 KB  |  306 lines

  1. #ifndef    lint
  2. static char SccsId[]= "@(#)win_events.c    V1.28    3/13/95";
  3. #endif
  4. /*
  5. |    file name - win_events.c
  6. |===================================================================
  7. |
  8. |    This program demonstrates how to use the window event routines
  9. |       to gather events from a DataViews window.  It uses
  10. |       VOloWinEventPoll, which gets the next event from the queue.
  11. |       Also, it shows how a typical application might respond to
  12. |    some of the new event types such as V_RESIZE, V_EXPOSE, and
  13. |    V_WINDOW_QUIT.
  14. |
  15. |       Events are passed to our event request handler so the input
  16. |       objects will update. In this example, the graphs are updated
  17. |       only if the input object took user input.
  18. |
  19. |       In addition, this example shows how to specify the dimensions
  20. |       and name of a window created using TscOpenSet.  If you want
  21. |       to see a summary of the events to standard output as they
  22. |       occur, rename the executable "win_eventsdb.x" and invoke it
  23. |       from the command line.
  24. |
  25. |       Generate a window QUIT event or type <q|Q> to exit.
  26. |
  27. |
  28. |===================================================================
  29. */
  30. #include <windows.h>
  31. /*
  32.  *  DV-Tools header files
  33.  */
  34. #include "std.h"                /* <stdio.h> etc., scalar & macro definitions */
  35. #include "dvstd.h"              /* public types & constants */
  36. #include "dvtools.h"            /* constants used by T routines */
  37. #include "dvGR.h"               /* constants used by window mgt & GR routines */
  38. #include "VOstd.h"              /* constants used by VO & VOob routines */
  39. #include "Tfundecl.h"           /* T routines (screens, drawports & views) */
  40. #include "VOfundecl.h"          /* VO routines (objects) */
  41. #include "VUerfundecl.h"        /* VUer routines (event handling routines) */
  42. #include "GRfundecl.h"          /* GR routines (interface to display device) */
  43. #include "VUfundecl.h"          /* VU routines (utilities) */
  44.  
  45. /* Constants */
  46. #define  DVPATH            (char *)NULL
  47. #define  DISPFORMS_STB     (char *)NULL
  48. #define  DVDEVICE          (char *)NULL
  49. #define  DVCOLORTABLE      (char *)NULL
  50. #define  VIEW_NAME       "multi1.v"
  51. #define  SCREEN_VIEWPORT   (RECTANGLE *)NULL
  52. #define  DRAWING_VIEWPORT  (RECTANGLE *)NULL
  53. #define  WIN_EVENTS_DBG    "win_eventsdb.x"
  54.  
  55. /*
  56.  *   MAIN PROGRAM
  57.  */
  58. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  59.                      LPSTR lpCmdLine,  int nCmdShow  )
  60. {
  61.   INT argc = 0;
  62.   CHAR **argv;
  63.   /*
  64.    *  program arguments
  65.    *    argv[1] - display device (default is DVDEVICE)
  66.    */
  67.  
  68.   /* Define & initialize device name and view filename */
  69.   char *device_name = DVDEVICE; /* default device name */
  70.   char *view_name = VIEW_NAME;  /* default view name */
  71.  
  72.   /* Define display variables */
  73.   OBJECT screen;                /* display device, the window */
  74.   DRAWPORT drawport;            /* how & where to display picture, picture 
  75.                                    frame */
  76.   VIEW view;                    /* picture representation of the view file */
  77.  
  78.   /* Control loop variables */
  79.   OBJECT location;              /* the event representation */
  80.   WINEVENT *we;                 /* structure storing details of event */
  81.   int event_req_status;         /* status of event requests */
  82.  
  83.   /* Other variables */
  84.   int screenx,                  /* new width of window in pixels */
  85.     screeny;                    /* new height of window in pixels */
  86.   int Quit = NO;                /* flag to quit program */
  87.  
  88.  
  89.   /*-----------------
  90.    *   Initialization
  91.    *
  92.    *   TInit:    perform the initialization of DV-Tools
  93.    *             TInit reads your configuration file and any
  94.    *             environment variables or logical names set.
  95.    */
  96.   make_argv(&argc,&argv,GetCommandLine());
  97.   TInit( DVPATH, DISPFORMS_STB );
  98.  
  99.   /*
  100.    *   TscOpenSet:  opens a device as a screen object using
  101.    *            specified attributes
  102.    *
  103.    *   Set exposure block to YES to insure the window
  104.    *   is ready for drawing when TdpDraw is called.
  105.    */
  106.   if (argc > 1)
  107.     device_name = argv[1];
  108.   screen = TscOpenSet (device_name, DVCOLORTABLE,
  109.                        V_WINDOW_NAME, "win_events",
  110.                        V_WINDOW_WIDTH, 400,
  111.                        V_WINDOW_HEIGHT, 400,
  112.                        V_X_EXPOSURE_BLOCK, YES,
  113.                        V_ACTIVE_CURSOR, V_END_OF_LIST);
  114.   if (!screen)
  115.     {
  116.       printf ("Must specify device on command line or");
  117.       printf (" in DataViews configuration file.\n");
  118.       S_EXIT (EXIT_ERR);
  119.     }
  120.  
  121.   /*
  122.    *   VOscWinEventMask:  sets the screen's window event mask
  123.    */
  124.   VOscWinEventMask ((ULONG) V_KEYPRESS | V_KEYRELEASE |
  125.                             V_BUTTONPRESS | V_BUTTONRELEASE |
  126.                             V_ENTERNOTIFY | V_MOTIONNOTIFY | V_LEAVENOTIFY |
  127.                             V_EXPOSE | V_RESIZE | V_WINDOW_QUIT,
  128.             (ULONG) 0);
  129.  
  130.   /*
  131.    *   TviLoad:   Load a view in from a file,
  132.    *              user supplied view or default view of multi1.v
  133.    *   TdpCreate: Create a drawport.
  134.    *              The drawport is attached to the screen object
  135.    *              specified while view specifies the view to be
  136.    *              displayed on the screen.
  137.    */
  138.   view = TviLoad (view_name);
  139.   if (!view)
  140.     {
  141.       printf ("Could not load view from file ");
  142.       printf ("%s.\n", view_name);
  143.       S_EXIT (EXIT_ERR);
  144.     }
  145.   drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
  146.  
  147.   /*
  148.    *   TscErase: Erase the entire screen in the default
  149.    *         background color
  150.    *   TdpDraw:  Draw the contents of the drawport
  151.    */
  152.   TscErase (screen);
  153.   TdpDraw (drawport);
  154.  
  155.  
  156.   /*--------------------
  157.    *   Control loop
  158.    *
  159.    *   Poll the event queue for window events specified by the
  160.    *   window mask.  Handle each of the events as they happen.
  161.    *   Events occurring within input objects will be handled
  162.    *   through the event request handler VUerHandleLocEvent.
  163.    *   Updates are performed if an input object used the
  164.    *   the event.
  165.    */
  166.   FOREVER
  167.   {
  168.     /*
  169.      *  VOloWinEventPoll:  Polls for the next window event.
  170.      *               The polling mode used is V_WAIT.
  171.      *               Therefore, VOloWinEventPoll does not
  172.      *               return until a masked event is
  173.      *               generated.  V_WAIT always produces
  174.      *               a valid location object.
  175.      */
  176.     location = VOloWinEventPoll (V_WAIT);
  177.  
  178.     /*
  179.      *  VOloType:  returns the type of event.  These types
  180.      *           match event types specified in VOscWinEventMask.
  181.      */
  182.     switch (VOloType (location))
  183.       {
  184.  
  185.       case V_EXPOSE:
  186.         /*
  187.          *  VOloRegion:  Returns a rectangle representing the
  188.          *          exposed region on the screen.
  189.          *  TscRedraw:   After erasing, redraws all the drawports
  190.          *          in the screen.
  191.          *  A portion of the window has been exposed and needs
  192.          *  to be redrawn.
  193.          */
  194.         TscRedraw (screen, VOloRegion (location));
  195.         break;
  196.  
  197.       case V_RESIZE:
  198.         /*
  199.          *  The window size has been changed.
  200.          *  TscReset:  Resets all screen drawports after
  201.          *        window resizing
  202.          *  GRaspect_ratio:  Gets the size of the screen in pixels
  203.          *
  204.          *  Print the new size of the window to standard output.
  205.          */
  206.         TscReset (screen);
  207.         GRaspect_ratio (&screenx, &screeny);
  208.         printf ("Window Size:    %d %d\n", screenx, screeny);
  209.         break;
  210.  
  211.       case V_WINDOW_QUIT:
  212.         /*
  213.          * User requests a window quit.
  214.          * Print message for quitting after V_WINDOW_QUIT
  215.          */
  216.         printf ("Quitting...\n");
  217.         Quit = YES;
  218.         break;
  219.  
  220.       case V_KEYPRESS:
  221.         /*
  222.          *  Check key selected.
  223.          *  VOloKeySym:  Returns the key symbol value of the
  224.          *         location object
  225.          *  If the key symbol represents the characters 'q'
  226.          *  or 'Q' then quit the program.
  227.          */
  228.         switch (VOloKeySym (location))
  229.           {
  230.           case 'q':
  231.           case 'Q':
  232.             Quit = YES;
  233.             break;
  234.  
  235.           default:
  236.             break;
  237.           }
  238.         break;
  239.  
  240.       case V_KEYRELEASE:
  241.       case V_BUTTONPRESS:
  242.       case V_BUTTONRELEASE:
  243.       case V_MOTIONNOTIFY:
  244.         /*
  245.          *  VUerHandleLocEvent: Service the event.
  246.          *            This routine will check if the
  247.          *            event is used by any input objects
  248.          *            that are in the view.
  249.          */
  250.         event_req_status = VUerHandleLocEvent (location);
  251.  
  252.         /*
  253.          * Update view only if an input object used the event
  254.          * TdpDrawNext: Update all dynamic objects within a
  255.          *              drawport's view.
  256.          */
  257.         if (event_req_status != INPUT_UNUSED)
  258.           TdpDrawNext (drawport);
  259.         break;
  260.  
  261.       default:
  262.         break;
  263.       }
  264.  
  265.     /*
  266.      *  VOloWinEventGet:   Returns the window event structure of
  267.      *               the location object.
  268.      *  VUweReportEvent:   Reports window events at a specified
  269.      *               level of detail. Level 3 reports
  270.      *               information relevant to the event type.
  271.      *
  272.      *  To report window event information, rename the executable
  273.      *  image of "win_events.x" to "win_eventsdb.x".  Invoke this
  274.      *  executable from the command line.
  275.      */
  276.     if (!strcmp (argv[0], WIN_EVENTS_DBG))
  277.       {
  278.         we = (WINEVENT *) VOloWinEventGet (location);
  279.         VUweReportEvent (we, 3);
  280.         printf ("\n");
  281.       }
  282.  
  283.     /* exit the program */
  284.     if (Quit == YES)
  285.       break;
  286.   }
  287.  
  288.  
  289.   /*--------------------
  290.    *   Termination
  291.    *
  292.    *   TscErase:     Erase the entire screen in the default
  293.    *                 background color
  294.    *   TdpDestroy:   Destroy the drawport,
  295.    *   TviDestroy:   Destroy the view, freeing the allocated memory
  296.    *   TscCloseCurrentScreen:  Close the current display screen
  297.    *   TTerminate:   Perform the clean-up for DV-Tools
  298.    */
  299.   TscErase (screen);
  300.   TdpDestroy (drawport);
  301.   TviDestroy (view);
  302.   TscCloseCurrentScreen ();
  303.   TTerminate ();
  304.   return EXIT_OK;
  305. }
  306.